package com.self.home.colorlinez;

import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;

import com.mikepenz.iconics.view.IconicsImageView;
import com.self.home.colorlinez.util.ConstantUtils;
import com.self.home.colorlinez.view.GameLayout;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.ViewById;

@EActivity(R.layout.activity_main)
public class MainActivity extends AppCompatActivity {

    @ViewById
    GameLayout gameLayout;

    @ViewById
    IconicsImageView nextBall1;

    @ViewById
    IconicsImageView nextBall2;

    @ViewById
    IconicsImageView nextBall3;

    @ViewById
    TextView scoreText;

    @ViewById
    TextView nowScoreText;

    @AfterViews
    void init() {
        gameLayout.setShowNextBallListener((colors) -> {
            nextBall1.setColor(colors[0]);
            nextBall2.setColor(colors[1]);
            nextBall3.setColor(colors[2]);
        });

        gameLayout.setScoreChangeListener((score) -> {
            int maxScore = ConstantUtils.getMaxScore(MainActivity.this);
            if (score > maxScore) {
                scoreText.setText(score + "");
                ConstantUtils.setMaxScore(MainActivity.this, score + "");
            } else {
                scoreText.setText(maxScore + "");
            }
            nowScoreText.setText(score + "");
        });

        int maxScore = ConstantUtils.getMaxScore(MainActivity.this);
        scoreText.setText(maxScore + "");
    }
}
